package it.fflabs.dynscript.mapsexample.client.model;

import com.google.gwt.core.client.JavaScriptObject;

import it.fflabs.dynscript.client.model.JsData;

/**
 * <b>Project</b> : gwt-dynScript-mapsExample<br>
 *
 * <b>Class</b> : INGVResult<br>
 * 
 * Comment : 
 * <br><hr>
 * 
 * @author Francesco Foresti
 * 
 * 30/mag/2012
 * 
 */
public class INGVResult extends JsData<INGVResult> {
	protected INGVResult() {}

	/*
	 * {
	 * "created_at":"Tue,29 May 2012 17:26:02 +0000",
	 * "from_user":"INGVterremoti",
	 * "from_user_id":121049123,
	 * "from_user_id_str":"121049123",
	 * "from_user_name":"INGVterremoti",
	 * "geo":
	 * {
	 * "coordinates":[42.8000,6.0300],
	 * "type":"Point"
	 * },
	 * "id":207523205995429888,
	 * "id_str":"207523205995429888",
	 * "iso_language_code":"in",
	 * "metadata":
	 * {
	 * "result_type":"recent"
	 * },
	 * "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/837990328\/logo_INGV_normal.png",
	 * "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/837990328\/logo_INGV_normal.png",
	 * "source":"&lt;a href=&quot;http:\/\/www.supertweet.net&quot;
	 * rel=&quot;nofollow&quot;&gt;SuperTweetAPI&lt;\/a&gt;",
	 * "text":"#terremoto Ml:2.0 2012-05-29 17:15:24 UTC Lat=42.80 Lon=6.03 Prof=10.0Km Prov=Western Mediterranean Sea",
	 * "to_user":null,
	 * "to_user_id":0,
	 * "to_user_id_str":"0",
	 * "to_user_name":null
	 * }
	 */

	public final native String getText() /*-{
		return this.text;
	}-*/;

	public final native JavaScriptObject getCoordinates() /*-{
		return this.geo.coordinates;
	}-*/;

	public final native double getLatitude() /*-{
		return this.geo.coordinates[0];
	}-*/;

	public final native double getLongitude() /*-{
		return this.geo.coordinates[1];
	}-*/;

	/**
	 * Performs a custom equality test on two {@link INGVResult}s.
	 * This is necessary since GWT's implementations of {@link JavaScriptObject#equals} and
	 * {@link JavaScriptObject#hashCode} must be final, and does not behave well w.r.t.
	 * the content of objects. <br>
	 * This implementation checks whether the 2 objects involved have the same content
	 * in the "text" field. This is sufficient for our purposes.
	 * 
	 * @param other
	 * @return true if the "other" param equals this.
	 */
	public final boolean equalsTo(INGVResult other) {
		if (other == null)
			return false;
		String text = this.getText();
		String otherText = other.getText();
		if (text == null && otherText != null) {
			return false;
		} else if (otherText == null && text != null) {
			return false;
		}
		return text.equals(otherText);
	}
}